home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / OS Utilities / TestQD / TestGestalt.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  2.3 KB  |  98 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        TestGestalt.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by:     
  7.  
  8.     Copyright:    Copyright © 1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/23/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. #ifndef __CTYPE__
  24. #include <CType.h>
  25. #endif
  26.  
  27. #ifndef __OSUTILS__
  28. #include <OSUtils.h>
  29. #endif
  30.  
  31. #ifndef __STDIO__
  32. #include <StdIO.h>
  33. #endif
  34.  
  35. #ifndef __GESTALTEQU__
  36. #include <GestaltEqu.h>
  37. #endif
  38.  
  39. #ifndef __TYPES__
  40. #include <Types.h>
  41. #endif
  42.  
  43. #include <Traps.h>
  44.  
  45. #define    TRUE            0xFF
  46. #define    FALSE            0
  47.  
  48. Boolean TrapAvailable(short theTrap);
  49.  
  50. // check to see if a given trap is implemented. We follow IM VI-3-8.
  51. Boolean TrapAvailable(short theTrap)
  52. {
  53.     TrapType theTrapType;
  54.     short numToolboxTraps;
  55.     
  56.     if ((theTrap & 0x0800) > 0)
  57.         theTrapType = ToolTrap;
  58.     else
  59.         theTrapType = OSTrap;
  60.  
  61.     if (theTrapType == ToolTrap)
  62.     {
  63.         theTrap = theTrap & 0x07ff;
  64.         if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xaa6e, ToolTrap))
  65.             numToolboxTraps = 0x0200;
  66.         else
  67.             numToolboxTraps = 0x0400;
  68.         if (theTrap >= numToolboxTraps)
  69.             theTrap = _Unimplemented;
  70.     };
  71.  
  72.     return (NGetTrapAddress(theTrap, theTrapType) != NGetTrapAddress(_Unimplemented, ToolTrap));
  73. }
  74.  
  75.  
  76. void main()
  77. {
  78. OSErr        err;
  79. long        feature;
  80.  
  81. if (TrapAvailable(_Gestalt)) {
  82.     err = Gestalt(gestaltQuickdrawVersion, &feature);
  83.     if (!err) {
  84.         if ((feature & 0x0f00) == 0x0000)
  85.             printf ("We have Original QuickDraw version 0.%x\n", (feature & 0x00ff));
  86.         else if ((feature & 0x0f00) == 0x0100)
  87.             printf ("We have 8 Bit QuickDraw version 1.%x\n", (feature & 0x00ff));
  88.         else if ((feature & 0x0f00) == 0x0200)
  89.             printf ("We have 32 Bit QuickDraw version 2.%x\n", (feature & 0x00ff));
  90.         else
  91.             printf ("We don't have QD\n");
  92.         }
  93.     else 
  94.         printf ("Gestalt err = %i\n",err);
  95.     }
  96. else
  97.     printf ("No Gestalt\n");
  98. }